﻿using System.Collections.Generic;
using ProjNet.CoordinateSystems.Transformations;
using SharpMap.Geometries;
using SharpMap.Providers;
using SharpMap.Styles;

namespace SharpMap.Layers
{
    public abstract class BaseLayer : ILayer
    {
        /// <summary>
        /// Minimum visibility zoom, including this value
        /// </summary>
        public double MinVisible { get; set; }

        /// <summary>
        /// Maximum visibility zoom, excluding this value
        /// </summary>
        public double MaxVisible { get; set; }

        /// <summary>
        /// Specified whether the layer is rendered or not
        /// </summary>
        public bool Enabled { get; set; }

        /// <summary>
        /// Specify the opacity of the layer between 0 - 1
        /// </summary>
        public double Opacity { get; set; }

        /// <summary>
        /// Gets or sets the name of the layer
        /// </summary>
        public string LayerName { get; set; }

        /// <summary>
        /// Gets or sets the SRID of this VectorLayer's data source
        /// </summary>
        public int SRID { get; set; }

        public ICoordinateTransformation CoordinateTransformation { private get; set; }

        /// <summary>
        /// Returns the extent of the layer
        /// </summary>
        /// <returns>Bounding box corresponding to the extent of the features in the layer</returns>
        public virtual BoundingBox Envelope { get; set; }

        public event FeedbackEventHandler Feedback;

        public BaseLayer(string layerName) : this()
        {
            this.LayerName = layerName;
        }

        public BaseLayer()
        {
            Enabled = true;
            MinVisible = 0;
            Opacity = 1;
            MaxVisible = double.MaxValue;
        }

        public abstract IEnumerable<IFeature> GetFeaturesInView(BoundingBox box, double resolution);

        public override string ToString()
        {
            return LayerName;
        }

        protected void OnFeedback(string message)
        {
            if (Feedback != null)
            {
                Feedback(this, new FeedbackEventArgs() { Message = message });
            }
        }
    }
}
